package com.asia5b.a5mall.shop.adapter

import android.widget.ImageView
import android.widget.TextView
import com.asia5b.a5mall.middleware.model.shop.AbsGoodsModel

import com.asia5b.a5mall.middleware.utils.CurrencyPriceBuilder3
import com.asia5b.a5mall.middleware.utils.WImageLoader
import com.asia5b.a5mall.middleware.utils.judge
import com.asia5b.a5mall.shop.R
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder

/**
 * @param isMulti 是否是多列
 */
class ShopAllGoodsAdapter(list: ArrayList<AbsGoodsModel>, var isMulti: Boolean) :
        BaseQuickAdapter<AbsGoodsModel, BaseViewHolder>((isMulti).judge(R.layout.goodsitem_shopall_multi, R.layout.goodsitem_shopall), list) ,
        LoadMoreModule{
    init {
        addChildClickViewIds(R.id.iv_searchgoods_addcart)
    }
    override fun convert(helper: BaseViewHolder, item: AbsGoodsModel) {
        if (isMulti) {
            multi(helper, item)
        } else {
            single(helper, item)
        }

    }

    fun single(helper: BaseViewHolder, item: AbsGoodsModel) {
        //图片
        val iv_searchgoods_img = helper.getView<ImageView>(R.id.iv_searchgoods_img)
        WImageLoader.displayImage(item.absGoodsImageUrl, iv_searchgoods_img)
        //商品名
        helper.setText(R.id.tv_searchgoods_goodsname, item.absGoodsName)
        //价格
        val tv_searchgoods_price = helper.getView<TextView>(R.id.tv_searchgoods_price)
        CurrencyPriceBuilder3().run {
            textView = tv_searchgoods_price
            price = item.absGoodsPrice
            priceList = item.absGoodsPriceList
            build14_18()
        }
        //销量
        helper.setText(R.id.tv_searchgoods_buycount, item.absGoodsSellCountAndGradeText)

    }

    fun multi(helper: BaseViewHolder, item: AbsGoodsModel) {
        //图片
        val iv_shophome_img = helper.getView<ImageView>(R.id.iv_shophome_img)
        WImageLoader.displayImage(item.absGoodsImageUrl, iv_shophome_img)
        //商品名
        helper.setText(R.id.iv_shophome_goodsname, item.absGoodsName)
        //价格
        val tv_shophome_newprice = helper.getView<TextView>(R.id.tv_shophome_newprice)
        CurrencyPriceBuilder3().run {
            textView = tv_shophome_newprice
            price = item.absGoodsPrice
            priceList = item.absGoodsPriceList
            build14_18()
        }
        //销量
        helper.setText(R.id.tv_shophome_buycount, item.absGoodsSellCountText)
    }
}